package com.ruoyi.web.controller.basicInformation;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.system.basicInformation.domain.TArea;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.basicInformation.vo.TAreaVo;
import com.ruoyi.system.basicInformation.bo.TAreaQueryBo;
import com.ruoyi.system.basicInformation.bo.TAreaAddBo;
import com.ruoyi.system.basicInformation.bo.TAreaEditBo;
import com.ruoyi.system.basicInformation.service.ITAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 区域管理Controller
 * 
 * @author ruoyi
 * @date 2022-08-08
 */
@Api(value = "区域管理控制器", tags = {"区域管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/basicInformation/area")
public class TAreaController extends BaseController {

    private final ITAreaService iTAreaService;

    /**
     * 查询区域管理列表
     */
    @ApiOperation("查询区域管理列表")
    @GetMapping("/list")
    public TableDataInfo<TAreaVo> list(TAreaQueryBo bo) {
        startPage();
        List<TAreaVo> list = iTAreaService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出区域管理列表
     */
    @ApiOperation("导出区域管理列表")
    @Log(title = "区域管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TAreaVo> export(TAreaQueryBo bo) {
        List<TAreaVo> list = iTAreaService.queryList(bo);
        ExcelUtil<TAreaVo> util = new ExcelUtil<TAreaVo>(TAreaVo.class);
        return util.exportExcel(list, "区域管理");
    }

    /**
     * 获取区域管理详细信息
     */
    @ApiOperation("获取区域管理详细信息")
    @GetMapping("/{id}")
    public AjaxResult<TAreaVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTAreaService.queryById(id));
    }

    /**
     * 新增区域管理
     */
    @ApiOperation("新增区域管理")
    @Log(title = "区域管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TAreaAddBo bo) {
        return toAjax(iTAreaService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改区域管理
     */
    @ApiOperation("修改区域管理")
    @Log(title = "区域管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TAreaEditBo bo) {
        return toAjax(iTAreaService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除区域管理
     */
    @ApiOperation("删除区域管理")
    @Log(title = "区域管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTAreaService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    @GetMapping("/treeselect")
    public AjaxResult treeselect(TArea dept)
    {
        List<TArea> depts = iTAreaService.selectDeptList(dept);
        return AjaxResult.success(iTAreaService.buildDeptTreeSelect(depts));
    }
}
